home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / amigadoslibrary / fgets.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  1KB  |  55 lines

  1. /* FGets.c   V1.1   93-03-03                   */
  2. /* ROM library: "dos.library/FGets", (V36+)    */
  3. /* Copyright 1993, Anders Bjerin, Amiga C Club */
  4.  
  5. #include <dos/dos.h>
  6.  
  7. #include <clib/dos_protos.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. #define BUFFER_LENGTH 80
  12.  
  13. UBYTE *version = "$VER: FGets 1.1";
  14.  
  15. int main( int argc, char *argv[] );
  16. int main( int argc, char *argv[] )
  17. {
  18.   BPTR my_file;
  19.   UBYTE my_buffer[ BUFFER_LENGTH ];
  20.   STRPTR ok_ptr;
  21.  
  22.  
  23.   /* Open an already existing file: */
  24.   my_file = Open( "RAM:Shakespeare.doc", MODE_OLDFILE );
  25.   if( !my_file )
  26.     exit( 20 );
  27.  
  28.   /* Collect the first line: (If the line is longer than        */
  29.   /* BUFFER_LENGTH, the remaining part will be read next time.) */
  30.   ok_ptr = FGets( my_file, my_buffer, BUFFER_LENGTH );
  31.  
  32.   /* As long as we have not reached the end of the file */
  33.   /* or have found an error we stay in the while loop:  */
  34.   while( ok_ptr )
  35.   {
  36.     /* Print the collected string: */
  37.     printf( "%s", my_buffer );
  38.     
  39.     /* Get next line: (Or the remaining part of the  */
  40.     /* last one if the whole line did not fit in the */
  41.     /* buffer the first time.)                       */
  42.     ok_ptr = FGets( my_file, my_buffer, BUFFER_LENGTH );
  43.   }
  44.  
  45.   /* EOF or Error? */
  46.   if( IoErr() )
  47.     printf( "Error while reading!\n" );
  48.   else
  49.     printf( "End Of File!\n" );
  50.  
  51.   Close( my_file );
  52.  
  53.   exit( 0 );
  54. }
  55.